#include "main.h"
#include <math.h>
int main(int argc, char* argv[]) {
	struct complex_struct c1 = {1.0, 2.0};
	printComplex(c1);

	struct complex_struct c2 = {1.0, -2.0};
	printComplex(c2);

	printf("加: ");
	printComplex(add(c1, c2));
	printf("减: ");
	printComplex(sub(c1, c2));
	printf("乘: ");
	printComplex(mult(c1, c2));
	printf("除: ");
	printComplex(div(c1, c2));
	return 0;
}

int printComplex(struct complex_struct c) {
	if (c.type == 1) {
		printf("(%8.2f,%8.2fi)", c.x, c.y);
	} else {
		printf("%.2fe^i%.2f", c.x, c.y);
	}
	printf("\n");
	return 0;
}

struct complex_struct add(struct complex_struct c, struct complex_struct d) {
	c.x = c.x + d.x;
	c.y = c.y + d.y;
	return c;
}
struct complex_struct sub(struct complex_struct c, struct complex_struct d) {
	c.x = c.x - d.x;
	c.y = c.y - d.y;
	return c;
}
struct complex_struct mult(struct complex_struct c, struct complex_struct d) {
	return make_from_magn_angle(magnitude(c) * magnitude(d), angle(c) + angle(d));
}
struct complex_struct div(struct complex_struct c, struct complex_struct d) {
	return make_from_magn_angle(magnitude(c) / magnitude(d), angle(c) - angle(d));
}

double real_part(struct complex_struct c) {
	return c.x;
}

double image_part(struct complex_struct c) {
	return c.y;
}
double magnitude(struct complex_struct c) {
	return sqrt(c.x * c.x + c.y * c.y);
}
double angle(struct complex_struct c) {
	return atan2(c.y, c.x);
}
struct complex_struct make_from_real_image(double x, double y) {
	struct complex_struct z;
	z.type = RECTANGULAR;
	z.x = x;
	z.y = y;
	return z;
}

struct complex_struct make_from_magn_angle (double r, double a) {
	struct complex_struct z;
	z.type = RECTANGULAR;
	z.x = r * cos(a);
	z.y = r * sin(a);
	return z;
}
